//请求方式常量
window.POST = "post";
window.GET = "get";
window.PUT = "put";
window.DELETE = "delete";

//接口数据和请求对象
window.apiMap = {};
window.api = {};

//合并接口数据
Object.assign(
  apiMap,
  require("./common_api"),
  require("./account_api"),
  require("./personal_center_api"),
);

//遍历接口数据,合成请求对象
for(let k in apiMap) {
	//请求类型,请求路径,请求配置
	let type = apiMap[k].type;
	let url = apiMap[k].url;

	api[k] =  function(data, conf) {
		//优先级: 调用配置 > 默认配置 > 空配置 
		let config = conf || apiMap[k].config || {};

		//根据各个请求类型,分类执行axios请求
		if(type == GET) {
			config.params = data;
			return axios.get(url, config);
		}
		if(type == POST || type == null) {
			return axios.post(url, data, config);
		}
		if(type == PUT) {
			return axios.put(url, data, config);
		}
		if(type == DELETE) {
			config.params = data;
			return axios.delete(url, config);
		}
	}
}
